from devicetest.aw.OpenHarmony import CommonOH
from devicetest.core.test_case import TestCase, Step

from aw.common import common_setup, common_teardown
from aw.pom import Setting, DeskTop


class PreTest_RK3568_Basic_Setting_3800(TestCase, Setting):
    # 预置条件：
    # 烧写目标版本后，正常进入桌面
    # 测试步骤：
    # 1.进入桌面，点击设置-用户和帐号-当前登录-添加用户
    # 2.点击输入框输入昵称，点击添加
    # 3.点击切换
    # 预期结果：
    # 1.可正常进入到添加用户界面
    # 2.点击输入框可唤醒键盘，输入昵称，点击添加显示"切换到新用户吗?"弹窗
    # 3.点击切换可正常切换到新用户，新用户应用功能正常

    def __init__(self, controllers):
        self.TAG = self.__class__.__name__
        TestCase.__init__(self, self.TAG, controllers)

    def setup(self):
        common_setup(self.Phone1)

    def process(self):
        Step('步骤1：进入桌面，点击设置-用户和帐号-当前登录-添加用户')
        CommonOH.startAbility(self.Phone1, self.ability_name, self.bundle_name)
        CommonOH.wait(self.Phone1, 1)
        CommonOH.swipe(self.Phone1, **DeskTop.swipe_up)
        CommonOH.wait(self.Phone1, 3)
        CommonOH.touchByText(self.Phone1, '用户和帐户')
        CommonOH.touchByText(self.Phone1, '当前登录')
        CommonOH.touchByText(self.Phone1, '添加用户')
        Step('预期结果1：可正常进入到添加用户界面')
        CommonOH.checkIfTextExist(self.Phone1, '添加新用户')
        Step('步骤2：点击输入框输入昵称，点击添加')
        CommonOH.touchByType(self.Phone1, 'TextInput')
        CommonOH.wait(self.Phone1, 1)
        CommonOH.inputTextByType(self.Phone1, type='TextInput', content='test')
        Step('预期结果2.1：点击输入框可唤醒键盘，输入昵称，点击添加显示"切换到新用户吗?"弹窗')
        CommonOH.checkIfTextExist(self.Phone1, 'space')
        Step('预期结果2.2：点击添加显示"切换到新用户吗?"弹窗')
        CommonOH.touchByText(self.Phone1, '添加')
        CommonOH.wait(self.Phone1, 3)
        CommonOH.checkIfTextExist(self.Phone1, '取消')
        CommonOH.checkIfTextExist(self.Phone1, '切换')
        Step('步骤3：点击切换')
        CommonOH.touchByText(self.Phone1, '切换')
        Step('预期结果3：点击切换可正常切换到新用户，新用户应用功能正常')
        CommonOH.wait(self.Phone1, 5)
        CommonOH.swipe(self.Phone1, **DeskTop.swipe_up)
        CommonOH.checkIfTypeExist(self.Phone1, 'Badge')
        CommonOH.startAbility(self.Phone1, self.ability_name, self.bundle_name)
        CommonOH.wait(self.Phone1, 0.5)
        CommonOH.swipe(self.Phone1, **DeskTop.swipe_up)
        CommonOH.wait(self.Phone1, 3)
        CommonOH.touchByText(self.Phone1, '用户和帐户')
        CommonOH.wait(self.Phone1, 0.5)
        CommonOH.checkIfTextExist(self.Phone1, '当前登录')
        CommonOH.checkIfTextExist(self.Phone1, 'test')

    def teardown(self):
        common_teardown(self.Phone1, self.bundle_name)
